package rev3;

import static org.junit.Assert.*;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Random;
import java.util.StringTokenizer;

import org.junit.Assert;
import org.junit.Test;

import rev3.MyString;
import rev3.NodeMyString;

public class Rev3TestGetsVerifyPuts {

	/**
	 * This verifies certain objects are now present in the DHT after being 'Put'
	 */
	@Test
	public void test2()
	{
		NodeMyString remoteNode = null;
		try {
            Registry registry = LocateRegistry.getRegistry();
            
            String name = "n5";
            // Get the remote ref
            remoteNode = (NodeMyString) registry.lookup(name);
            System.out.println("found node "+name);

            MyString retMyStr = remoteNode.get("16::billy");
            assertTrue("clinton".equalsIgnoreCase(retMyStr.getMyString()) );
            
            name = "n30";
            // Get the remote ref
            remoteNode = (NodeMyString) registry.lookup(name);
            System.out.println("found node "+name);

            retMyStr = remoteNode.get("56::frank");
            assertTrue("frankenstein".equalsIgnoreCase(retMyStr.getMyString()) );
            
            // This lookup is a namespace wrap-around
            name = "n1";
            // Get the remote ref
            remoteNode = (NodeMyString) registry.lookup(name);
            System.out.println("found node "+name);

            retMyStr = remoteNode.get("4::depak");
            assertTrue("patri".equalsIgnoreCase(retMyStr.getMyString()) );


            
        } catch (Exception e) {
            System.err.println("NodeMyString exception:");
            e.printStackTrace();
            fail();
        }

	}

}
